package com.newhis.service.factory.impl;

import com.newhis.service.factory.AbstractFactory;
import com.newhis.service.shape.ShapeService;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 业务聚合
 *
 * @version [V2.0]
 * @package com.newhis.service.factory.impl;
 * @description:[用一句话描述该文件做什么]
 * @author: [zhuben]
 * @date: [2024-07-14 09:08]
 * @copyright: 2024 echovin.com
 */
@Service
public class ShapeFactory extends AbstractFactory implements ApplicationContextAware {

    public Map<String, ShapeService> map = new ConcurrentHashMap<>();
    @Override
    public ShapeService getShape(String shapeType) {
        ShapeService shapeService = map.get(shapeType);
        return shapeService;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String, ShapeService> beansOfType = applicationContext.getBeansOfType(ShapeService.class);
        Collection<ShapeService> values = beansOfType.values();
        for (ShapeService shapeService : values){
            String shapeType = shapeService.getShapeType();
            map.put(shapeType, shapeService);
        }
    }

}
